package com.teradata.observer.core;

import java.lang.reflect.Method;

/**
 * Created by lyndon on 2018/5/29.
 *
 * 创建一个事件
 */
public class Event {

    /*
     事件源和Trigger是不能set的
     */

    // 事件源
    private Object source;

    // 通知目标
    private Object target;

    // 回调
    private Method callback;

    // 触发
    private String trigger;

    // 触发时间
    private long triggerTime;



    public Event(Object target, Method callback) {
        this.target = target;
        this.callback = callback;
    }

    /**
     * 采用 default ，只能让同一个包内的类进行调用。
     * @param source
     * @return
     */
    Event setSource(Object source){
        this.source = source;
        return this;
    }

    public Object getSource() {
        return source;
    }


    public Object getTarget() {
        return target;
    }

    public void setTarget(Object target) {
        this.target = target;
    }

    public Method getCallback() {
        return callback;
    }

    public void setCallback(Method callback) {
        this.callback = callback;
    }

    /**
     * 同样也是default ，同一个包的类能调用
     * @param trigger
     * @return
     */
    Event setTrigger(String trigger) {
        this.trigger = trigger;
        return this;
    }

    public String getTrigger() {
        return trigger;
    }

    public long getTriggerTime() {
        return triggerTime;
    }

    public void setTriggerTime(long triggerTime) {
        this.triggerTime = triggerTime;
    }

    @Override
    public String toString() {
        return "Event{\n" +
                "\tsource=" + source + "\n" +
                "\t target=" + target + "\n" +
                "\t callback=" + callback + "\n" +
                "\t trigger='" + trigger + '\'' + "\n" +
                '}';
    }
}
